package com.ld.security.server.admin.modules.ge.api;

import com.ld.security.common.tomcat.anno.AjaxLogKey;
import  com.ld.security.server.admin.modules.ge.entity.GeModelEntity;
import com.ld.security.server.admin.modules.ge.po.SaveModelPo;
import com.ld.security.server.admin.modules.ge.po.GeModelArgsPo;
import  com.ld.security.server.admin.modules.ge.service.IGeModelService;
import com.ld.security.server.admin.modules.ge.util.ProjectUtil;
import com.ld.security.server.admin.modules.ge.vo.GeModelArgsVo;
import  com.ld.security.server.admin.modules.ge.vo.ModelDetailVo;
import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.tomcat.base.api.SuperApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Arrays;

@RestController
@Api(tags="模型Api管理")
@RequestMapping("/api/geModel")
public class  GeModelApi extends  SuperApi<GeModelEntity> {

    @Autowired
    private IGeModelService iGeModelService;


    @AjaxLogKey
    @RequestMapping(value = "/deleteModel",method = RequestMethod.POST)
    @ApiOperation("删除一个模型")
    public DataVo deleteModel(@Valid @RequestBody IdPo po) {
        iGeModelService.deleteModel(po.getId());
        return DataVo.ofMsg("模型删除成功");
    }

    @AjaxLogKey
        @RequestMapping(value = "/newModel",method = RequestMethod.POST)
    @ApiOperation("得到一个模型")
    public DataVo newModel(@RequestBody IdPo po){
        GeModelEntity model = new GeModelEntity();

        model.setViewId(po.getId());



        iGeModelService.save(model);
        ModelDetailVo vo = new ModelDetailVo();
        vo.setLinks(Arrays.asList());
        vo.setModel(model);
        vo.setFields(Arrays.asList());
        return DataVo.of(vo);
    }



    @AjaxLogKey
    @ApiOperation("得到模型详情")
    @RequestMapping(value = "/getModelDetail",method = RequestMethod.POST)
    public DataVo getModelDetail(@Valid @RequestBody IdPo po) {
        ModelDetailVo vo =  iGeModelService.getModelDetail(po.getId());
        DataVo dataVo =  DataVo.of(vo);

        return dataVo;
    }


    @AjaxLogKey
    @ApiOperation("详情模型更新")
    @RequestMapping(value = "/saveModel",method = RequestMethod.POST)
    public DataVo saveModel(@RequestBody SaveModelPo po) {
        iGeModelService.saveModel(po);
        return DataVo.ofMsg("修改模型成功");
    }

    @AjaxLogKey
    @ApiOperation("模型详情界面下拉参数")
    @RequestMapping(value = "/getGeModelArgs",method = RequestMethod.POST)
    public DataVo getGeModelArgsVo(@Valid @RequestBody GeModelArgsPo po) {
        String projectId = ProjectUtil.getDefProectId();

        po.setProjectId(projectId);
        GeModelArgsVo vo =  iGeModelService.getGeModelArgsVo(po);
        return DataVo.of(vo);
    }



}
